﻿function fireParentForm(LocationType, WebpartIdPermission, PermissionCode) {
}


function ClientSaveOnClick() {

    var ltype = $("#_locationLevelTypeSelect").val();
    if (ltype == "0") {
        alert("Chưa chọn cấp địa phương!");
        document.getElementById("_locationLevelTypeSelect").select();
        document.getElementById("divProcessing").innerHTML = "";
        return;
    }
    var locationid = $("#_locationsel").val();
    if (locationid == null) {
        alert("Địa phương không hợp lệ, vui lòng chọn lại!");
        document.getElementById("_locationsel").select();
        document.getElementById("divProcessing").innerHTML = "";
        return;
    }
    //locationid = document.getElementById("_locationsel").options[document.getElementById("_locationsel").selectedIndex].value;
    ngaynhap = document.getElementById("drpDayadaterecorded").options[document.getElementById("drpDayadaterecorded").selectedIndex].value + '/' + document.getElementById("drpMonthadaterecorded").options[document.getElementById("drpMonthadaterecorded").selectedIndex].value + '/' + document.getElementById("drpYearadaterecorded").options[document.getElementById("drpYearadaterecorded").selectedIndex].value;
    if (ngaynhap == "//") {
        alert("Bạn chưa nhập ngày nhập số liệu!");
        document.getElementById("drpDayadaterecorded").focus();
    }
   
    caythuocphien = document.getElementById("caythuocphien").value;
    scaythuocphien = document.getElementById("scaythuocphien").value;
    caycansa = document.getElementById("caycansa").value;
    scaycansa = document.getElementById("scaycansa").value;
    caykhac = document.getElementById("caykhac").value;
    scaykhac = document.getElementById("scaykhac").value;
    hotrong = document.getElementById("hotrong").value;
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";    
    value = Portal.SODC.IDIS.AddNewPlants.ServerSideAddNewPlants(locationid,ngaynhap,caythuocphien,scaythuocphien,caycansa,scaycansa,caykhac,scaykhac,hotrong).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value.replace("ERROR:", ""));
        document.getElementById("divProcessing").innerHTML = "";
        return;
    }
    alert(value);
    document.getElementById("divProcessing").innerHTML = "";
    ClientAddNewPlantsResetAllField();
}

function ClientUpdateSaveOnClick(recordid) {
    var ltype = $("#_locationLevelTypeSelect").val();
    var locationid = $("#_locationsel").val();
    if (typeof (locationid) == 'undefined' || locationid == null) {
        var LocationId_Curent = $("#locationcurrentid").val();
        locationid = LocationId_Curent;
    }
    //locationid = document.getElementById("_locationsel").options[document.getElementById("_locationsel").selectedIndex].value;
    ngaynhap = document.getElementById("drpDayudaterecorded").options[document.getElementById("drpDayudaterecorded").selectedIndex].value + '/' + document.getElementById("drpMonthudaterecorded").options[document.getElementById("drpMonthudaterecorded").selectedIndex].value + '/' + document.getElementById("drpYearudaterecorded").options[document.getElementById("drpYearudaterecorded").selectedIndex].value;
    if (ngaynhap == "//") {
        alert("Bạn chưa nhập ngày nhập số liệu!");
        document.getElementById("drpDayudaterecorded").focus();
    }
   
    caythuocphien = document.getElementById("caythuocphien").value;
    scaythuocphien = document.getElementById("scaythuocphien").value;
    caycansa = document.getElementById("caycansa").value;
    scaycansa = document.getElementById("scaycansa").value;
    caykhac = document.getElementById("caykhac").value;
    scaykhac = document.getElementById("scaykhac").value;
    hotrong = document.getElementById("hotrong").value;  
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    value = Portal.SODC.IDIS.UpdatePlants.ServerSideUpdatePlants(recordid, locationid, ngaynhap, caythuocphien, scaythuocphien, caycansa, scaycansa, caykhac, scaykhac, hotrong).value;
    if (value.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(value.replace("ERROR:", ""));
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    alert(value);
    window.close();
}

function ClientAddNewPlantsResetAllField() {
    document.getElementById("drpDayadaterecorded").selectedIndex = 0;
    document.getElementById("drpMonthadaterecorded").selectedIndex = 0;
    document.getElementById("drpYearadaterecorded").selectedIndex = 0;

    document.getElementById("caythuocphien").value = "";
    document.getElementById("scaythuocphien").value = "";
    document.getElementById("caycansa").value = "";
    document.getElementById("scaycansa").value = "";
    document.getElementById("caykhac").value = "";
    document.getElementById("scaykhac").value = "";
    document.getElementById("hotrong").value = "";
    document.getElementById("drpDayadaterecorded").focus();
}

function FilterFunc() {
    var levelid = document.getElementById("_locationLevelTypeSelect").selectedIndex;
    if (levelid == 0) {
        alert("Bạn chưa chọn cấp, địa phương!");
        return;
    }
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    setTimeout("RealFilterFunc('', 0, 30, 10, 0, 'RealFilterFunc')", 10);
}

function RealFilterFunc(belongsite, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    var ltype = $("#_locationLevelTypeSelect").val();
    if (ltype == "0") {
        alert("Chưa chọn cấp địa phương!");
        document.getElementById("divProcessing").innerHTML = "";
        return;
    }
    var LocationId = $("#_locationsel").val();
//    alert(LocationId);
    datefrom = document.getElementById("drpDayplantdatefrom").options[document.getElementById("drpDayplantdatefrom").selectedIndex].value + '/' + document.getElementById("drpMonthplantdatefrom").options[document.getElementById("drpMonthplantdatefrom").selectedIndex].value + '/' + document.getElementById("drpYearplantdatefrom").options[document.getElementById("drpYearplantdatefrom").selectedIndex].value;
    dateto = document.getElementById("drpDayplantdateto").options[document.getElementById("drpDayplantdateto").selectedIndex].value + '/' + document.getElementById("drpMonthplantdateto").options[document.getElementById("drpMonthplantdateto").selectedIndex].value + '/' + document.getElementById("drpYearplantdateto").options[document.getElementById("drpYearplantdateto").selectedIndex].value;
    retValue = Portal.SODC.IDIS.ListPlants.GetHtmlResult(ltype, LocationId, datefrom, dateto, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript).value;
    if (retValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(retValue.replace("ERROR:", ""));
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("resultcontent").innerHTML = retValue;
}

function ClientDeletePlants(recordid, belongsite, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    Msg = Portal.SODC.IDIS.ListPlants.GetConfirmDeleteMsg().value;
    if (confirm(Msg) == false) return;
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    RetValue = Portal.SODC.IDIS.ListPlants.ServerSideDeletePlants(recordid).value;
    if (RetValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(RetValue.replace("ERROR:", ""));
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    alert(RetValue);
    RealFilterFunc(belongsite, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript);
}

function ShowClientAddnewUrlForm() {
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    Url = Portal.SODC.IDIS.ListPlants.GetShowAddNewForm().value;
    if (Url.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(Url.replace("ERROR:", ""));
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    window.open(Url, "_blank");    
}

function ShowClientViewdetailsForm(recordid, belongsite, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    Url = Portal.SODC.IDIS.ListPlants.GetShowDetailsForm(recordid).value;
    if (Url.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(Url.replace("ERROR:", ""));
        return;
    }
    window.open(Url, "_blank");
    document.getElementById("divProcessing").innerHTML = "";
    RealFilterFunc(belongsite, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript);
}

function ShowClientUpdateUrlForm(recordid, belongsite, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    Url = Portal.SODC.IDIS.ListPlants.GetShowUpdateForm(recordid).value;
    if (Url.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(Url.replace("ERROR:", ""));
        return;
    }
    window.open(Url, "_blank");
    document.getElementById("divProcessing").innerHTML = "";
    RealFilterFunc(belongsite, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript);
    $("#pudatefrom").datepicker({ dateFormat: 'dd/mm/yy' });
}

function ShowClientUpdateUrlFromviewform(RecordId) {
    document.getElementById("divProcessing").innerHTML = "Hệ thống đang xử lý";
    Url = Portal.SODC.IDIS.DetailsPlants.GetShowUpdateForm(RecordId).value;
    if (Url.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(Url.replace("ERROR:", ""));
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    window.open(Url, "_self");
}

function ClientStatus() {
    alert("Chuyên mục này đang xây dựng!");
    return;
}

function ClientExportData() {
    //var levelid = document.getElementById("_locationLevelTypeSelect").selectedIndex;
    var ltype = $("#_locationLevelTypeSelect").val();
    if (ltype == 0) {
        alert("Bạn chưa chọn cấp, địa phương!");
        return;
    }
    var LocationId = $("#_locationsel").val();
    datefrom = document.getElementById("drpDayplantdatefrom").options[document.getElementById("drpDayplantdatefrom").selectedIndex].value + '/' + document.getElementById("drpMonthplantdatefrom").options[document.getElementById("drpMonthplantdatefrom").selectedIndex].value + '/' + document.getElementById("drpYearplantdatefrom").options[document.getElementById("drpYearplantdatefrom").selectedIndex].value;
    dateto = document.getElementById("drpDayplantdateto").options[document.getElementById("drpDayplantdateto").selectedIndex].value + '/' + document.getElementById("drpMonthplantdateto").options[document.getElementById("drpMonthplantdateto").selectedIndex].value + '/' + document.getElementById("drpYearplantdateto").options[document.getElementById("drpYearplantdateto").selectedIndex].value;

    Ret = Portal.SODC.IDIS.ListPlants.ServerExportData(ltype, LocationId, datefrom, dateto).value;
    if (Ret.indexOf("ERROR") != -1) {
        alert(Ret.replace("ERROR:", ""));
        return;
    } else {
        window.open(Ret, "_blank");
        //alert(Ret);
    }
}

function _locationLevelTypeSelectTypeForListCase() {
    var ltype = $("#_locationLevelTypeSelect").val();
    $("#SelectLocationZone").html(Portal.SODC.IDIS.ListPlants.ServerSideRenderLocationSelect(ltype).value);
}

function checkdate(date) {
    var validformat = /^\d{2}\/\d{2}\/\d{4}$/;
    var returnval = false;
    if (!validformat.test(date))
        alert("Nhập sai định dạng ngày tháng.");
    else {
        var dayfield = date.split("/")[0];
        var monthfield = date.split("/")[1];
        var yearfield = date.split("/")[2];
        var dayobj = new Date(yearfield, monthfield - 1, dayfield);
        if ((dayobj.getMonth() + 1 != monthfield) || (dayobj.getDate() != dayfield) || (dayobj.getFullYear() != yearfield))
            alert("Vui lòng nhập lại ngày tháng theo định dạng ngày/tháng/năm.");
        else
            returnval = true;
    }
    return returnval;
}